﻿using Common;
using Google.Cloud.Translation.V2;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace WebAppGoogleTranslation
{
    public class GoogleTranslateAppService : IGoogleTranslateAppService
    {
        private readonly TranslationClient translationClient;
        private readonly string apiKey = "AIzaSyCwIa8uDMPQ32kbOo7kXXiHaLlaLynJn6o";
        public GoogleTranslateAppService()
        {
            translationClient = TranslationClient.CreateFromApiKey(apiKey);
        }

        public async Task<IEnumerable<Language>> GetLanguagesApiAsync(string target = "en")
        {
            var url = $"https://translation.googleapis.com/language/translate/v2/languages?key={apiKey}&target={target}&model=nmt";
            var result = await Utils.SendAync(new HttpRequestMessage()
            {
                RequestUri = new System.Uri(url),
                Method = HttpMethod.Get,
            });

            return null;
        }

        public async System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Language>> GetLanguagesAsync(string target = "en")
        {
            var languages = await translationClient.ListLanguagesAsync(target);
            return languages;
        }
    }
}
